class LandmarksController < ApplicationController

  def index
    @landmarks = Landmarks.find(:all, :order => "package_id")
  end

#  def show
#    @landmarks = Landmarks.find(params[:id])
#    add_page_token(@landmarks)
#  end

  def new
    @landmark = Landmarks.new
  end

  def edit
    @landmark = Landmarks.find(params[:id])
    return self.unauthorized unless self.current_user.can('edit:landmark', @landmark)
    add_page_token(@landmark.name)
  end

  def create
	@landmark = Landmarks.new(params[:landmarks])
	return self.unauthorized unless self.current_user.can('create:landmark', @landmark)
	if @landmark.save
		flash[:notice] = 'Landmark was successfully created.'
		redirect_to(landmarks_path)
	else
		render :action => "new"
	end
  end

  def update 
	@landmark = Landmarks.find(params[:id])
	return self.unauthorized unless self.current_user.can('edit:landmark', @landmark)
	if @landmark.update_attributes(params[:landmarks])
		flash[:notice] = 'Landmark was successfully updated.'
		redirect_to(landmarks_path)
	else
		render :action => "edit"
	end
    	add_page_token(@landmark.name)
  end 


  def destroy
    @landmark = Landmarks.find(params[:id])
    return self.unauthorized unless self.current_user.can('delete:landmark', @landmark)
    @landmark.destroy

    redirect_to landmarks_path
  end

end
